{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "31d505ae",
   "metadata": {},
   "source": [
    "# PythonAl1-3阶段复习\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3e132e53-4c56-49cc-a718-074c0113b282",
   "metadata": {},
   "source": [
    "### 运算符\n",
    "`[]`列表类型 `{}`字典/集合类型 `()`元组类型 `' '|\" \"|''' '''`字符串\n",
    "\n",
    "运算优先级(现在数学课本上的比python(or and ==)高)\n",
    "运算符>逻辑判断符\n",
    "\n",
    "or 是一真(True)则真,全假则假\n",
    "> 或 要么 其中 符合就行 任意一条\n",
    "and 是一假(False)则假,全真则真\n",
    "> 必须 全都 并且 都\n",
    "\n",
    "/ 除法得到浮点型(小数点后1位)\n",
    "// 整除得到整型\n",
    "= 赋值\n",
    "== 判断"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "08f27e1e-f7e2-415d-8084-dbc19c9244fa",
   "metadata": {},
   "source": [
    "### 判断和循环语句\n",
    "\n",
    "#### for循环\n",
    "range()生成一个range类型列表,输出需要转为list\n",
    "range(开始,结束,步长)\n",
    "+ 开始(闭区间)\n",
    "+ 结束(开区间,取不到)\n",
    "+ 步长,隔几步\n",
    "\n",
    "> 开始可以忽略,默认从0开始\n",
    "> 步长也是不写,默认是1\n",
    "\n",
    "do…while循环不可用于python\n",
    "\n",
    "#### 区别\n",
    "continue结束当前循环过程,系鞋带\n",
    "break结束整个循环过程,腿断了\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "62b25644-1a8d-47d6-8038-d733ee9e9fe3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "#range(开始,结束,步长)\n",
    "#左闭右开 闭区间(能取到的值),开区间(不能取到)\n",
    "list(range(1,6,2))\n",
    "for i in range(5):\n",
    "    if i==3:\n",
    "        # break #结束整个循环,后面不干了,不跑了(腿断了)\n",
    "        continue#结束当次循环,下一圈接着跑(系鞋带)\n",
    "    print(i)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e0f47e05-74bc-4aeb-8df2-584009d5d5c5",
   "metadata": {},
   "source": [
    "### 列表\n",
    "\n",
    "1. 下标从0开始数\n",
    "   ##### 函数\n",
    "   + append() 末尾追加一个\n",
    "   + pop()   末尾删除一个\n",
    "   + insert()   插入任意位置\n",
    "   + remove() 删除任意位置\n",
    "   + clear() 全部删除\n",
    "\n",
    "#### 公共方法\n",
    "max()\n",
    "min()\n",
    "len()\n",
    "type()\n",
    "print()\n",
    "   \n",
    "#### 切片\n",
    "1. list[开始:结束:步长]  ---类似range\n",
    "2. :分割\n",
    "3. 左闭右开\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "91f46618-0668-4705-ae9b-ccac7bc17df6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 3, 5, 7]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "li = [1,2,3,4,5,6,7,8]\n",
    "print(li[0:7:2])\n",
    "max(li)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4b6e86d1-8761-406c-b4c6-65104a5f18f5",
   "metadata": {},
   "source": [
    "### 字典\n",
    "\n",
    "1. 字典是用来存键值对 key:value\n",
    "2. 用,分割多个键值对\n",
    "3. 用{}来表示字典\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "17df6ffd-1e7f-47d1-b206-1955a0203b23",
   "metadata": {},
   "source": [
    "range(0,5)中的参数,是左闭右开的,0可以取到,5取不到"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "16969cca-1cc2-4c5e-a928-1017e42f704c",
   "metadata": {},
   "source": [
    "切片 a[1:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "25d26241",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1+2+3\n"
     ]
    }
   ],
   "source": [
    "s = \"python\"\n",
    "# for i in s:\n",
    "#     print(i,end=\" \",sep=)\n",
    "print(1,2,3,sep=\"+\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "1ad2a69e-9de9-444c-90f3-bebcac72b96c",
   "metadata": {},
   "outputs": [],
   "source": [
    "#max是最大值,公共函数()\n",
    "#min是最小值\n",
    "s = [1,2,3,4]\n",
    "max(s)\n",
    "#列表方法中\n",
    "s.pop() #代表弹出最后一个元素,并返回\n",
    "s.clear()#方法可以清空列表\n",
    "s.append(1)#方法可以在列表末尾添加一个元素。\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "41c96e17-3f16-46c5-bce9-6cca841b64bb",
   "metadata": {},
   "source": [
    "列表的二要素 []  ,\n",
    "列表的下标都是从0开始数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1ad2a69e-9de9-444c-90f3-bebcac72b96c",
   "metadata": {},
   "source": [
    "字典的三要素 {} , :\n",
    "字典的元素都是成对出现的，中间用冒号隔开\n",
    "字典的新增是无中生有\n",
    "dict[key] = value"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cc3e17e4-8745-4f0f-b4f4-6d8875343e14",
   "metadata": {},
   "source": [
    "input() 语句输入的内容，一定是字符串类型的\n",
    "字符串不能进行减法操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "9a81d301-501a-4200-b58b-187cc6424710",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "该数是质数.\n"
     ]
    }
   ],
   "source": [
    "#判断质数\n",
    "#除了1和它本身外，不能被其他自然数整除\n",
    "def findPrime(m):\n",
    "    #从2到本身()不包含\n",
    "    for i in range(2,m):\n",
    "        #m%i==0代表被整除了\n",
    "        if m%i==0:\n",
    "            #返回否False\n",
    "            return False     #return会中断整个函数.循环也不会执行了\n",
    "    else:\n",
    "        #能执行到代表都没有被整除\n",
    "        return True\n",
    "n = int(input('请输入一个数:'))\n",
    "if  findPrime(n):\n",
    "    print(\"该数是质数.\")\n",
    "else:\n",
    "    print(\"该数不是质数.\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "ac57cb2c-608a-4823-8ab2-dee82ec125b5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "164\n"
     ]
    }
   ],
   "source": [
    "def tallest( a ):\n",
    "    m=0\n",
    "    for i in range( len(a) ):\n",
    "        if m<a[i]:\n",
    "            m=a[i]\n",
    "    print(m)\n",
    "n=[ 154 , 145 , 162 , 152,164 , 142 , 158 ]\n",
    "tallest(n)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9f5cec60-1171-468c-9b57-c289f43f1a48",
   "metadata": {},
   "outputs": [],
   "source": [
    "#判断质数\n",
    "#除了1和它本身外，不能被其他自然数整除\n",
    "def findPrime(m):\n",
    "    #从2到本身()不包含\n",
    "    for i in range(2,m):\n",
    "            #返回否False\n",
    "            return False     #return会中断整个函数.循环也不会执行了\n",
    "\n",
    "    else:\n",
    "\n",
    "        #能执行到代表都没有被整除\n",
    "        return True\n",
    "\n",
    "n = int(input('请输入一个数:'))\n",
    "\n",
    "if  findPrime(n):\n",
    "\n",
    "    print(\"该数是质数.\")\n",
    "\n",
    "else:\n",
    "\n",
    "    print(\"该数不是质数.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ac57cb2c-608a-4823-8ab2-dee82ec125b5",
   "metadata": {},
   "outputs": [],
   "source": [
    "def tallest( a ):\n",
    "\n",
    "    m=0\n",
    "\n",
    "    for i in range( len(a) ):\n",
    "\n",
    "        if m<a[i]:\n",
    "\n",
    "            m=a[i]\n",
    "\n",
    "    print(m)\n",
    "\n",
    "n=[ 154 , 145 , 162 , 152,164 , 142 , 158 ]\n",
    "\n",
    "tallest(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9f5cec60-1171-468c-9b57-c289f43f1a48",
   "metadata": {},
   "outputs": [],
   "source": [
    "while True:\n",
    "    a=float(input('请输入长（厘米）：'))\n",
    "    b=float(input('请输入宽（厘米）：'))\n",
    "    c=float(input('请输入高（厘米）：'))\n",
    "    #相加值\n",
    "    sum=a+b+c\n",
    "\n",
    "    #长、宽、高之和须小于或等于200厘米，且任意一边长度必须小于或等于80厘米\n",
    "    if sum<=200 and a<=80 and b<=80 and c<=80:\n",
    "        print('可以邮寄')\n",
    "    else:\n",
    "        print('不可以邮寄')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
